﻿using System;
using System.Threading;

namespace Coding4Fun.BoxingBots.Common
{
	public class EventHelper
	{
		public static void RaiseEvent<TE>(object sender, SynchronizationContext context, EventHandler<TE> eventHandler, EventArgs args) where TE : EventArgs
		{
			if(eventHandler != null)
			{
				if(context != null)
					context.Post(delegate { eventHandler(sender, (TE)args); }, null);
				else
					eventHandler(sender, (TE)args);
			}
		}
	}
}
